'use strict';
SSSAPP
  .controller('RootCtrl', ['$rootScope', '$rjax', function ($rootScope, $rjax) {
    $rootScope.showPanel = 'unvisiable';
    $rjax.post({
      url: '/Home/Util/ajaxGetWxJSSDK',
      data: {
        url: encodeURIComponent(location.href.split('#')[0])
      },
      callback: function (response) {
        //noinspection JSUnresolvedVariable
        if (response.rsc == '1001') {
          $rootScope.sdkinfo = response.data;
          //noinspection JSUnresolvedVariable
          wx.config({
            debug: false
            , // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
            appId: response.data.appId, // 必填，公众号的唯一标识
            timestamp: response.data.timestamp, // 必填，生成签名的时间戳
            nonceStr: response.data.nonceStr, // 必填，生成签名的随机串
            signature: response.data.signature,// 必填，签名，见附录1
            jsApiList: [
              response.data.jsApi1,
              response.data.jsApi2
            ] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
          });
          wx.error(function (res) {

          });
        }
      }
    });
  }])
  .controller('HomeCtrl', ['$scope', '$rjax', '$debounce', '$rootScope', '$state', function ($scope, $rjax, $debounce, $rootScope, $state) {
    // 获取首页的信息
    $scope.setDefaultIndexAndJump = function (v, href) {
      event.preventDefault();
      localStorage.setItem('homeCarouselDefaultIndex', v);
      location.href = href;
    };
    $scope.refresh = function () {
      $scope.activecate = null;
      $scope.slides = null;
      $rjax.get({
        url: '/Home/BlockManage/ajaxGetIndexInfo',
        callback: function (response) {
          $debounce(function () {
            //noinspection JSUnresolvedVariable
            if (response.rsc == '1001') {
              //noinspection JSUnresolvedVariable
              //$scope.slides = response.data.banner_list;
              $scope.defaultIndex = num_f(localStorage.getItem('homeCarouselDefaultIndex'));
              $scope.slides = response.data.banner_body_list;
              console.log($scope.defaultIndex);
              $scope.myInterval = 10000;
              $scope.noWrapSlides = false;
              //noinspection JSUnresolvedVariable
              $scope.list = response.data.commodity_list;
              //var sheight = $(document).height() - 47;
              //$('.carousel').height(sheight);
              $scope.cart = {};
              if (!empty(response.data.cart_list)) {
                angular.forEach(response.data.cart_list.list, function (data) {
                  $scope.cart[data.commodity_id] = data;
                });
              }
              //var video = new tvp.VideoInfo();
              //video.setVid("b0182n7netq");//视频vid
              //var player = new tvp.Player($(window).width(), $(window).width() * 5 / 9);//视频高宽
              //player.setCurVideo(video);
              //player.addParam("autoplay", "0");//是否自动播放，1为自动播放，0为不自动播放
              //player.addParam("wmode", "opaque");
              //player.addParam("pic", "http://img-idm.shishifresh.com/Public/uploadFiles/2016-01-22/c660c42b26d1c892175a0728f5bf8ff4.jpg");//默认图片地址
              //player.addParam("flashskin", "http://imgcache.qq.com/minivideo_v1/vd/res/skins/TencentPlayerMiniSkin.swf");//是否调用精简皮肤，不使用则删掉此行代码
              //player.write("home_player");
              //slide to right place
              //setTimeout(function () {
              //    var targetId = window.localStorage ? localStorage.getItem("targetId") : null;
              //    if (targetId != null) {
              //        $(window).scrollTop(document.getElementById(targetId).offsetTop);
              //        window.localStorage ? localStorage.removeItem("targetId") : null;
              //    }
              //}, 300);
            }
          });
        }
      });
    };
    $scope.ajaxGetIndexCommodities = function (id) {
      return false;
      if ($scope.activecate == id) {
        return false;
      }
      $rjax.get({
        url: '/Home/BlockManage/ajaxGetIndexCommodityByCateId',
        data: {
          category_id: id
        },
        callback: function (response) {
          $debounce(function () {
            //noinspection JSUnresolvedVariable
            if (response.rsc == '1001') {
              $scope.activecate = id;
              //noinspection JSUnresolvedVariable
              $scope.list = response.data.commodity_list;
            } else {
              $scope.activecate = id;
              $scope.list = null;
            }
          });
        }
      });
    };
    $scope.activecate = null;
    $scope.isActive = function (id) {
      if (id == $scope.activecate) {
        return 'active';
      } else {
        return '';
      }
    };
    $scope.refresh();
    //查询商品在购物车内的数量
    $scope.checkCart = function (id) {
      var num = 0;
      angular.forEach($scope.cart, function (data) {
        if (id == data.commodity_id) {
          num = data.commodity_num;
        }
      });
      return num;
    };
    //查询操作盘的状态
    $scope.checkOperate = function (id) {
      var num = 0;
      angular.forEach($scope.cart, function (data) {
        if (id == data.commodity_id) {
          num = data.commodity_num;
        }
      });
      if (num > 0) return 'show';
      return '';
    };
    //操作
    $scope.NumMinus = function (id) {
      if ($scope.cart[id].commodity_num <= 1) {
        $rjax.post({
          url: '/Home/Cart/ajaxDeleteCartOne',
          data: {
            commodity_id: $scope.cart[id].commodity_id,
            commodity_type: $scope.cart[id].commodity_type
          },
          callback: function (response) {
            //noinspection JSUnresolvedVariable
            if (response.rsc == '1001') {
              $debounce(function () {
                delete($scope.cart[id]);
              });
            } else {
              if (response.msg == '尚未登录') {
                $rootScope.showPanel = 'visiable';
              } else {
                easy_dialog({
                  content: response.msg
                });
              }
            }
          }
        });
      } else {
        $rjax.post({
          url: '/Home/Cart/ajaxUpdateCartNum',
          data: {
            commodity_id: $scope.cart[id].commodity_id,
            commodity_num: $scope.cart[id].commodity_num - 1,
            commodity_type: $scope.cart[id].commodity_type
          },
          callback: function (response) {
            $debounce(function () {
              //noinspection JSUnresolvedVariable
              if (response.rsc == '1001') {
                $scope.cart[id].commodity_num--;
              } else {
                if (response.msg == '尚未登录') {
                  $rootScope.showPanel = 'visiable';
                } else {
                  easy_dialog({
                    content: response.msg
                  });
                }
              }
            });
          }
        });
      }
    };
    $scope.NumPlus = function (id) {
      if (!empty($scope.cart[id])) {
        $rjax.post({
          url: '/Home/Cart/ajaxUpdateCartNum',
          data: {
            commodity_id: $scope.cart[id].commodity_id,
            commodity_num: $scope.cart[id].commodity_num + 1,
            commodity_type: $scope.cart[id].commodity_type
          },
          callback: function (response) {
            //noinspection JSUnresolvedVariable
            if (response.rsc == '1001') {
              $scope.cart[id].commodity_num++;
            } else {
              if (response.msg == '尚未登录') {
                $rootScope.showPanel = 'visiable';
              } else {
                easy_dialog({
                  content: response.msg
                });
              }
            }
          }
        })
      } else {
        var cart_json = '';
        angular.forEach($scope.list, function (data) {
          if (id == data.commodity_id) {
            cart_json = '{"commodity_id":"' + data.commodity_id + '", "commodity_num":1, "commodity_type":"common"}';
          }
        });
        $rjax.post({
          url: '/Home/Cart/ajaxAddCart',
          data: {
            cart_info: cart_json
          },
          callback: function (response) {
            $debounce(function () {
              //noinspection JSUnresolvedVariable
              if (response.rsc == '1001') {
                $scope.cart[id] = {
                  commodity_id: id,
                  commodity_num: 1,
                  commodity_type: 'common'
                }
              } else {
                //noinspection JSUnresolvedVariable
                if (response.toLogin == 1) {
                  $rootScope.showPanel = 'visiable';
                } else {
                  easy_dialog({
                    content: response.msg
                  });
                }
              }
            });
          }
        })
      }
    };
    // 计算当前购物车内的商品总数
    $scope.countCart = function () {
      var num = 0;
      angular.forEach($scope.cart, function (data) {
        num += num_f(data.commodity_num);
      });
      return num;
    };
    //去账户中心
    $scope.goAccount = function () {
      $rjax.get({
        url: '/Home/Login/ajaxCheckLogin',
        callback: function (response) {
          $debounce(function () {
            //noinspection JSUnresolvedVariable
            if (response.rsc == '1002') {
              $rootScope.showPanel = 'visiable';
            } else {
              $state.go('center');
            }
          });
        }
      })
    };
    //去购物车
    $scope.goCart = function () {
      $rjax.get({
        url: '/Home/Login/ajaxCheckLogin',
        callback: function (response) {
          $debounce(function () {
            //noinspection JSUnresolvedVariable
            if (response.rsc == '1002') {
              $rootScope.showPanel = 'visiable';
            } else {
              $state.go('cart');
            }
          });
        }
      })
    };
  }])
  .controller('CartCtrl', ['$scope', '$rjax', '$location', '$debounce', '$rootScope', '$state', function ($scope, $rjax, $location, $debounce, $rootScope, $state) {
    $rjax.get({
      url: '/Home/Login/ajaxCheckLogin',
      callback: function (response) {
        $debounce(function () {
          //noinspection JSUnresolvedVariable
          if (response.rsc == '1002') {
            $rootScope.showPanel = 'visiable';
          }
        });
      }
    });
    $scope.total_sum = 0;
    $scope.cartList = null;
    $scope.visiable = false;
    $rjax.get({
      url: '/Home/Cart/ajaxGetCartList',
      callback: function (response) {
        if (!empty(response.data)) {
          $scope.visiable = true;
          $scope.cartList = response.data.list;
          $scope.commInfo = response.data.commInfo;
        }
      }
    });
    $scope.ClearGarbage = function () {
      var buttons = {
        '取消': function () {
          this.hide();
        },
        '清空': function () {
          this.hide();
          $rjax.get({
            url: '/Home/Cart/ajaxDeleteCartAll',
            callback: function (response) {
              //noinspection JSUnresolvedVariable
              if (response.rsc == '1001') {
                $debounce(function () {
                  $scope.visiable = false;
                  $scope.cartList = null;
                });
              }
            }
          })
        }
      };
      easy_dialog({
        buttons: buttons,
        content: '确认清空购物袋吗？'
      });
    };
    $scope.NumMinus = function (index) {
      if ($scope.cartList[index].commodity_num <= 1) {
        var buttons = {
          '取消': function () {
            this.hide();
          },
          '删除': function () {
            $rjax.post({
              url: '/Home/Cart/ajaxDeleteCartOne',
              data: {
                commodity_id: $scope.cartList[index].commodity_id,
                commodity_type: $scope.cartList[index].commodity_type
              },
              callback: function (response) {
                //noinspection JSUnresolvedVariable
                if (response.rsc == '1001') {
                  $debounce(function () {
                    $scope.cartList.splice(index, 1);
                    if ($scope.cartList.length <= 0) {
                      $scope.visiable = false;
                      $scope.cartList = null;
                    }
                  });
                }
              }
            });
            this.hide();
          }
        };
        $debounce(function () {
          easy_dialog({
            buttons: buttons,
            content: '确认删除' + $scope.commInfo[$scope.cartList[index].commodity_id].name + '吗？'
          });
        }, 300);
      } else {
        $scope.cartList[index].commodity_num--;
        $rjax.post({
          url: '/Home/Cart/ajaxUpdateCartNum',
          abort_type: 'abort',
          data: {
            commodity_id: $scope.cartList[index].commodity_id,
            commodity_num: $scope.cartList[index].commodity_num,
            commodity_type: $scope.cartList[index].commodity_type
          }
        })
      }
    };
    $scope.NumPlus = function (index) {
      $scope.cartList[index].commodity_num++;
      $rjax.post({
        url: '/Home/Cart/ajaxUpdateCartNum',
        abort_type: 'abort',
        data: {
          commodity_id: $scope.cartList[index].commodity_id,
          commodity_num: $scope.cartList[index].commodity_num,
          commodity_type: $scope.cartList[index].commodity_type
        }
      })
    };
    $scope.totalSum = function () {
      if ($scope.cartList == null) {
        return 0;
      }
      var sum = 0;
      $scope.cartList.forEach(function (v) {
        //noinspection JSUnresolvedVariable
        sum += $scope.commInfo[v.commodity_id].sale_price * v.commodity_num;
      });
      return sum;
    };
    $scope.GoSettle = function () {
      $rjax.get({
        url: '/home/login/ajaxCheckLogin',
        callback: function (response) {
          $debounce(function () {
            //noinspection JSUnresolvedVariable
            if (response.rsc == '1001') {
              $state.go('order', {
                biztype: 0
              });
            } else {
              $rootScope.showPanel = 'visiable';
            }
          }, 300);
        }
      })
    }
  }])
  .controller('GponCtrl', ['$scope', '$rjax', '$debounce', '$rootScope', '$state', '$sce', '$interval', function ($scope, $rjax, $debounce, $rootScope, $state, $sce, $interval) {
    // 联合登录
    //$rjax.post({
    //    url: '/Home/Util/ajaxHrefCheck',
    //    data: {
    //        url: encodeURIComponent(location.href)
    //    },
    //    callback: function (response) {
    //        if (response.href.length > 0) {
    //            location.href = response.href;
    //            return true;
    //        }
    //    }
    //});

    $scope.GoBuild = function (setid) {
      $state.go('gpon', {
        page: 'home',
        setid: setid,
        gponid: null
      });
    };
    // 跳转逻辑
    if (empty($state.params.page)) {
      $state.go('gpon', {
        setid: $state.params.setid,
        page: 'home'
      });
    }
    $scope.$watch($state.params.page, function () {
      $scope.getGponInfo();
      $scope.state = $state.params.page;
      $scope.setid = $state.params.setid;
      $scope.gponid = $state.params.gponid;
      if ($scope.state == 'mygpon') {
        $scope.getMyGponList();
      } else if ($scope.state == 'hotgpon') {
        $scope.getHotGponList();
      }
    });
    $scope.toShare = false;
    $scope.toggleShare = function () {
      $scope.toShare = !$scope.toShare;
    };
    //轮播图
    $scope.myInterval = 5000;
    $scope.noWrapSlides = false;
    //状态
    $scope.changemygpon = function () {
      $rjax.get({
        url: '/Home/Login/ajaxCheckLogin',
        callback: function (response) {
          $debounce(function () {
            //noinspection JSUnresolvedVariable
            if (response.rsc == '1002') {
              $rootScope.showPanel = 'visiable';
            } else {
              $state.go('gpon', {
                setid: $state.params.setid,
                page: 'mygpon'
              });
            }
          });
        }
      })
    };
    $scope.changehotgpon = function () {
      $state.go('gpon', {
        setid: $state.params.setid,
        page: 'hotgpon'
      });
    };
    $scope.changehome = function () {
      $state.go('gpon', {
        setid: $state.params.setid,
        page: 'hotgpon'
      });
    };
    //各种接口
    // 获取我的团
    $scope.getMyGponList = function () {
      if (empty($state.params.setid)) {
        return false;
      }
      var params = {
        set_id: $state.params.setid
      };
      $rjax.get({
        url: '/Home/Groupon/ajaxMyGponList',
        data: params,
        callback: function (response) {
          if (!empty(response.data)) {
            $scope.mygponlist = response.data;
            $scope.buttons = response.buttons;
          }
        }
      });
    };
    //获取热团
    $scope.getHotGponList = function () {
      if (empty($state.params.setid)) {
        return false;
      }
      var params = {
        set_id: $state.params.setid
      };
      $rjax.get({
        url: '/Home/Groupon/ajaxHotGponList',
        data: params,
        callback: function (response) {
          if (!empty(response.data)) {
            $scope.hotlist = [];
            angular.forEach(response.data, function (data) {
              data.rate = $sce.trustAsHtml(data.rate);
              $scope.hotlist.push(data);
            });
          }
        }
      });
    };
    // 建团
    $scope.buildGpon = function () {
      if (empty($state.params.setid)) {
        easy_dialog({
          content: '参数错误'
        });
        return false;
      }
      var params = {
        set_id: $state.params.setid
      };
      $rjax.post({
        url: '/Home/Groupon/ajaxBuildGpon',
        data: params,
        callback: function (response) {
          $debounce(function () {
            //noinspection JSUnresolvedVariable
            if (response.rsc == '1001') {
              var buttons = {
                '确认': function () {
                  this.hide();
                  $state.go('gpon', {
                    setid: $state.params.setid,
                    page: 'home',
                    gponid: response.data
                  });
                }
              };
              easy_dialog({
                buttons: buttons,
                content: '建团成功'
              });
            } else { //noinspection JSUnresolvedVariable
              if (response.toLogin == 1) {
                $rootScope.showPanel = 'visiable';
              } else {
                easy_dialog({
                  content: response.msg
                });
              }
            }
          });
        }
      });
    };
    // 参团
    $scope.joinGpon = function () {
      if (empty($state.params.setid) || empty($state.params.gponid)) {
        easy_dialog({
          content: '参数错误'
        });
        return false;
      }
      var params = {
        set_id: $state.params.setid,
        gpon_id: $state.params.gponid
      };
      $rjax.post({
        url: '/Home/Groupon/ajaxJoinGpon',
        data: params,
        callback: function (response) {
          $debounce(function () {
            //noinspection JSUnresolvedVariable
            if (response.rsc == '1001') {
              var buttons = {
                '确认': function () {
                  this.hide();
                  $scope.getGponInfo();
                }
              };
              easy_dialog({
                buttons: buttons,
                content: '参团成功'
              });
            } else { //noinspection JSUnresolvedVariable
              if (response.toLogin == 1) {
                $rootScope.showPanel = 'visiable';
              } else {
                easy_dialog({
                  content: response.msg
                });
              }
            }
          });
        }
      });
    };
    $scope.showuserlist = function () {
      if (empty($scope.extinfo))
        return false;
      //noinspection JSUnresolvedVariable
      return empty($scope.extinfo.user_list);
    };
    // 获取团信息
    $scope.getGponInfo = function () {
      if (empty($state.params.setid)) {
        location.href = '/Home/index/notfound';
      }
      $rjax.get({
        url: '/Home/Groupon/ajaxGetGponInfo',
        data: {
          set_id: $state.params.setid,
          gpon_id: $state.params.gponid
        },
        callback: function (response) {
          $debounce(function () {
            if (!empty(response.data)) {
              //noinspection JSUnresolvedVariable 团购配置
              $scope.setinfo = response.data.set_info;
              //noinspection JSUnresolvedVariable 页面的状态信息
              $scope.extinfo = response.data.extend_info;
              var dateObj = parseDateString($scope.setinfo.death_time);
              $scope.endtimeSec = dateObj.getTime();
              var intid = $interval(function () {
                $scope.instTime = new Date().getTime();
                if ($scope.endtimeSec - $scope.instTime <= 0) {
                  $scope.countdowntime = '已结束';
                  $interval.cancel(intid);
                  return false;
                }
                $scope.second = Math.floor((($scope.endtimeSec - $scope.instTime) / 1000) % 60);
                $scope.minute = Math.floor((($scope.endtimeSec - $scope.instTime) / 1000 / 60) % 60);
                $scope.hour = Math.floor((($scope.endtimeSec - $scope.instTime) / 1000 / 60 / 60) % 24);
                $scope.day = Math.floor((($scope.endtimeSec - $scope.instTime) / 1000 / 60 / 60) / 24);
                if ($scope.day >= 1)
                  $scope.countdowntime = $scope.day + '天' + fix2datenum($scope.hour) + '小时' + fix2datenum($scope.minute) + '分';
                else
                  $scope.countdowntime = fix2datenum($scope.hour) + '小时' + fix2datenum($scope.minute) + '分';
              }, 1000);
              // 商品信息
              //noinspection JSUnresolvedVariable
              $scope.cominfo = response.data.set_info.commodity_info;
              // 图案的图片信息
              $scope.setpic = [];
              //noinspection JSUnresolvedVariable
              angular.forEach(response.data.set_info.set_pic_url, function (data) {
                var tmpobj = {
                  src: data
                };
                $scope.setpic.push(tmpobj);
              });
              // 规则
              //noinspection JSUnresolvedVariable
              var tmparr = response.data.set_info.set_desc.split('|');
              $scope.rules = [];
              angular.forEach(tmparr, function (data) {
                $scope.rules.push($sce.trustAsHtml(data));
              });
              // 分享的图片
              //noinspection JSUnresolvedVariable
              $scope.setlogo = response.data.set_info.set_logo;
              // 格式化时间
              //noinspection JSUnresolvedVariable
              var fmtedstr = parseDateString(response.data.set_info.sale_cycle.dispatch_datetime);
              $scope.setinfo.sale_cycle.dispatch_datetime = (fmtedstr.getMonth() + 1) + '月' + fmtedstr.getDate() + '日';

              //noinspection JSUnresolvedVariable
              wx.ready(function () {
                wx.onMenuShareTimeline({
                  title: response.data.extend_info.share_title, // 分享标题
                  desc: '食市', // 分享描述
                  link: location.href, // 分享链接
                  imgUrl: 'http://img-idm.shishifresh.com/Public/uploadFiles/2016-01-22/c660c42b26d1c892175a0728f5bf8ff4.jpg', // 分享图标
                  success: function () {
                    // 用户确认分享后执行的回调函数
                    alert('分享成功');
                  },
                  cancel: function () {
                    // 用户取消分享后执行的回调函数
                  }
                });
                //noinspection JSUnresolvedVariable
                wx.onMenuShareAppMessage({
                  title: response.data.extend_info.share_title, // 分享标题
                  desc: '食市', // 分享描述
                  link: location.href, // 分享链接
                  imgUrl: 'http://img-idm.shishifresh.com/Public/uploadFiles/2016-01-22/c660c42b26d1c892175a0728f5bf8ff4.jpg', // 分享图标
                  success: function () {
                    // 用户确认分享后执行的回调函数
                  },
                  cancel: function () {
                    // 用户取消分享后执行的回调函数
                  }
                });
              });
            }
          });
        }
      });
    };
  }])
  .controller('DetailCtrl', ['$scope', '$rjax', '$debounce', '$rootScope', '$state', function ($scope, $rjax, $debounce, $rootScope, $state) {
    $rootScope.detail_id = $state.params.cid;
    $(window).scrollTop(0);
    $scope.cid = $state.params.cid;
    window.localStorage.setItem("targetId", $state.params.cid); // set target id
    $scope.num = 0;
    $scope.type = 'common';
    $scope.former = $state.params.former;
    $scope.refresh = function () {
      $rjax.get({
        url: '/Home/Commodity/ajaxGetCommodityInfo',
        data: {
          commodity_id: $scope.cid
        },
        callback: function (response) {
          $debounce(function () {
            $scope.base_info = response.data.base_info;
            $scope.cart_list = response.data.cart_list;
            $scope.cart = [];
            try {
              angular.forEach(response.data.cart_list.list, function (data) {
                $scope.cart[data.commodity_id] = data;
              });
            } catch (e) {

            }
            $scope.ext_imgs = response.data.ext_imgs;
            //noinspection JSUnresolvedVariable
            $scope.recommand = response.data.collocations;
            if ($scope.base_info.is_limit)
              $scope.limited = '库存' + $scope.base_info.left_num + '个';
            else
              $scope.limited = '不限量供应';
            if (isExist(response.data.last_sale_cycle)) {
              var dateinfo = parseDateString(response.data.last_sale_cycle.collect_datetime);
              $scope.timelimited = dateinfo.getDate() + '号' + fix2datenum(dateinfo.getHours()) + ':' + fix2datenum(dateinfo.getMinutes()) + '截止抢鲜';
            }
            // vedio set
            if ($scope.base_info.video_id != undefined && $scope.base_info.video_id != null) {
              var video = new tvp.VideoInfo();
              video.setVid($scope.base_info.video_id);//视频vid
              var player = new tvp.Player($(window).width(), $(window).width() * 5 / 9);//视频高宽
              player.setCurVideo(video);
              player.addParam("autoplay", "0");//是否自动播放，1为自动播放，0为不自动播放
              player.addParam("wmode", "opaque");
              player.addParam("pic", "http://img-idm.shishifresh.com/Public/uploadFiles/2016-01-22/c660c42b26d1c892175a0728f5bf8ff4.jpg");//默认图片地址
              player.addParam("flashskin", "http://imgcache.qq.com/minivideo_v1/vd/res/skins/TencentPlayerMiniSkin.swf");//是否调用精简皮肤，不使用则删掉此行代码
              player.write("detail_player");
            }
            //noinspection JSUnresolvedVariable
            wx.ready(function () {
              wx.onMenuShareTimeline({
                title: $scope.base_info.name, // 分享标题
                desc: $scope.base_info.brief_desc, // 分享描述
                link: location.href, // 分享链接
                imgUrl: $scope.base_info.brief_pic, // 分享图标
                success: function () {
                  // 用户确认分享后执行的回调函数
                  alert('分享成功');
                },
                cancel: function () {
                  // 用户取消分享后执行的回调函数
                }
              });
              //noinspection JSUnresolvedVariable
              wx.onMenuShareAppMessage({
                title: $scope.base_info.name, // 分享标题
                desc: $scope.base_info.brief_desc, // 分享描述
                link: location.href, // 分享链接
                imgUrl: $scope.base_info.brief_pic, // 分享图标
                success: function () {
                  // 用户确认分享后执行的回调函数
                },
                cancel: function () {
                  // 用户取消分享后执行的回调函数
                }
              });
            });
          });
        }
      })
    };
    $scope.GoBack = function () {
      if (!empty($state.params.former)) {
        $state.go($state.params.former);
      } else {
        $state.go('home');
      }
    };
    $scope.refresh();
    //查询商品在购物车内的数量
    $scope.checkCart = function (id) {
      try {
        if ($scope.cart[id] == undefined || $scope.cart[id] == null)
          return 0;
        return $scope.cart[id].commodity_num;
      } catch (e) {
      }
    };
    //查询操作盘的状态
    $scope.checkOperate = function (id) {
      try {
        if ($scope.cart[id].commodity_num > 0) {
          return 'show';
        } else {
          return '';
        }
      } catch (e) {
        return '';
      }
    };
    //操作
    $scope.NumMinus = function (id) {
      if ($scope.cart[id].commodity_num <= 1) {
        $rjax.post({
          url: '/Home/Cart/ajaxDeleteCartOne',
          data: {
            commodity_id: $scope.cart[id].commodity_id,
            commodity_type: $scope.cart[id].commodity_type
          },
          callback: function (response) {
            //noinspection JSUnresolvedVariable
            if (response.rsc == '1001') {
              $debounce(function () {
                delete($scope.cart[id]);
              });
            } else {
              if (response.msg == '尚未登录') {
                $rootScope.showPanel = 'visiable';
              } else {
                easy_dialog({
                  content: response.msg
                });
              }
            }
          }
        });
      } else {
        $rjax.post({
          url: '/Home/Cart/ajaxUpdateCartNum',
          data: {
            commodity_id: $scope.cart[id].commodity_id,
            commodity_num: $scope.cart[id].commodity_num - 1,
            commodity_type: $scope.cart[id].commodity_type
          },
          callback: function (response) {
            $debounce(function () {
              //noinspection JSUnresolvedVariable
              if (response.rsc == '1001') {
                $scope.cart[id].commodity_num--;
              } else {
                if (response.msg == '尚未登录') {
                  $rootScope.showPanel = 'visiable';
                } else {
                  easy_dialog({
                    content: response.msg
                  });
                }
              }
            });
          }
        });
      }
    };
    $scope.NumPlus = function (id) {
      if (!empty($scope.cart[id])) {
        $rjax.post({
          url: '/Home/Cart/ajaxUpdateCartNum',
          data: {
            commodity_id: $scope.cart[id].commodity_id,
            commodity_num: num_f($scope.cart[id].commodity_num) + 1,
            commodity_type: $scope.cart[id].commodity_type
          },
          callback: function (response) {
            //noinspection JSUnresolvedVariable
            if (response.rsc == '1001') {
              $scope.cart[id].commodity_num++;
            } else {
              if (response.msg == '尚未登录') {
                $rootScope.showPanel = 'visiable';
              } else {
                easy_dialog({
                  content: response.msg
                });
              }
            }
          }
        })
      } else {
        var cart_json = '{"commodity_id":"' + id + '", "commodity_num":1, "commodity_type":"common"}';
        $rjax.post({
          url: '/Home/Cart/ajaxAddCart',
          data: {
            cart_info: cart_json
          },
          callback: function (response) {
            $debounce(function () {
              //noinspection JSUnresolvedVariable
              if (response.rsc == '1001') {
                $scope.cart[id] = {
                  commodity_id: id,
                  commodity_num: 1,
                  commodity_type: 'common'
                }
              } else {
                //noinspection JSUnresolvedVariable
                if (response.toLogin == 1) {
                  $rootScope.showPanel = 'visiable';
                } else {
                  easy_dialog({
                    content: response.msg
                  });
                }
              }
            });
          }
        })
      }
    };
  }])
  .controller('CenterCtrl', ['$scope', '$rjax', '$state', '$debounce', function ($scope, $rjax, $state, $debounce) {
    $rjax.get({
      url: '/Home/Login/ajaxCheckLogin',
      callback: function (response) {
        $debounce(function () {
          //noinspection JSUnresolvedVariable
          if (response.rsc == '1002') {
            $rootScope.showPanel = 'visiable';
          }
        });
      }
    });
    $scope.doLogout = function () {
      $rjax.get({
        url: '/Home/Login/ajaxLogout',
        callback: function (response) {
          //noinspection JSUnresolvedVariable
          if (response.rsc == '1001') {
            $state.go('home');
          }
        }
      })
    };
  }])
  .controller('OrderCenterCtrl', ['$scope', '$rjax', '$debounce', '$state', function ($scope, $rjax, $debounce, $state) {
    $rjax.get({
      url: '/Home/Login/ajaxCheckLogin',
      callback: function (response) {
        $debounce(function () {
          //noinspection JSUnresolvedVariable
          if (response.rsc == '1002') {
            $rootScope.showPanel = 'visiable';
          }
        });
      }
    });
    //按钮组
    $scope.radioModel = empty($state.params.state) ? 2 : num_f($state.params.state);
    $scope.changeState = function (state) {
      // <!-- 订单状态： 2：待支付 1：已支付 0：已废除 -->
      $state.go('ordercenter', {
        pageno: 1,
        state: state
      });
    };
    //分页
    $scope.pageno = empty($state.params.pageno) ? 1 : $state.params.pageno;
    $scope.pagesize = 15;
    $scope.pageChange = function () {
      $state.go('ordercenter', {
        pageno: $scope.pageinfo.pageno,
        state: $scope.radioModel,
        pagesize: $scope.pagesize
      });
    };
    //获取信息
    $scope.refresh = function () {
      var param = {};
      switch ($scope.radioModel) {
        case 1:
          param = {
            pageno: $scope.pageno,
            pagesize: $scope.pagesize,
            order_page: 1,
            payment_status: 10
          };
          break;
        case 0:
          param = {
            pageno: $scope.pageno,
            pagesize: $scope.pagesize,
            order_page: 0
          };
          break;
        default:
          param = {
            pageno: $scope.pageno,
            pagesize: $scope.pagesize,
            order_page: 1,
            payment_status: 1
          };
          break;
      }
      $rjax.get({
        url: '/Home/Order/ajaxGetOrderList',
        data: param,
        callback: function (response) {
          $debounce(function () {
            $scope.orderlist = response.data.list;
            //noinspection JSUnresolvedVariable
            $scope.pageinfo = response.data.page_info;
          })
        }
      })
    };
    $scope.refresh();
    $scope.cancelOrder = function (orderid) {
      var buttons = {
        '不取消': function () {
          this.hide();
        },
        '确认取消': function () {
          this.hide();
          var data = {
            order_id: orderid
          };
          $rjax.post({
            url: '/Home/Order/ajaxCancelOrder',
            data: data,
            callback: function () {
              $debounce(function () {
                $scope.refresh();
              })
            }
          })
        }
      };
      easy_dialog({
        buttons: buttons,
        content: '确认要取消这个订单吗？'
      });
    };
  }])
  .controller('OrderCtrl', ['$rootScope', '$scope', '$rjax', '$debounce', '$state', function ($rootScope, $scope, $rjax, $debounce, $state) {
    $scope.submit = false;
    //判断业务获取商品和排期
    if (empty($state.params.biztype)) {
      $state.go('order', {
        biztype: 0
      });
      return false;
    } else if ($state.params.biztype == 1) { //团购
      $scope.setid = $state.params.setid;
      $scope.gponid = $state.params.gponid;
    }
    $scope.GoBack = function () {
      if (empty($state.params.biztype) || $state.params.biztype == 0) {
        $state.go('cart');
      } else if ($state.params.biztype == 1) { //团购
        $state.go('gpon', {
          page: 'home',
          setid: $state.params.setid,
          gponid: $state.params.gponid
        });
      }
    };
    // 去选择地址
    $scope.GoExpres = function () {
      if ($state.params.biztype == 1) {
        $state.go('express', {
          former: 'order',
          biztype: 1,
          setid: $scope.setid,
          gponid: $scope.gponid
        });
      } else {
        $state.go('express', {
          former: 'order'
        });
      }
    };
    $scope.biztype = $state.params.biztype;
    if ($scope.biztype == 0) {
      //常规
      if ($scope.cart == undefined) {
        $scope.total_amount = 0;
        $rjax.get({
          url: '/Home/Order/ajaxGetCartOrder',
          callback: function (response) {
            $debounce(function () {
              //noinspection JSUnresolvedVariable
              if (response.rsc == '1001') {
                if (empty(response.data.cart_list)) {
                  $state.go('home');
                }
                $scope.cue = response.data.cue;
                $scope.cartInfo = response.data.cart_list.list;
                //noinspection JSUnresolvedVariable
                $scope.express = response.data.firstaddress;
                //noinspection JSUnresolvedVariable
                $scope.total_amount = response.data.cart_list.sum.sale_sum;
                $scope.shipping_fee = response.data.shipping_fee;
                $scope.sale_cycle = response.data.sale_cycle;
                $scope.dispatch_datetime = response.data.sale_cycle.dispatch_datetime.split(' ')[0];
              }
            });
          }
        })
      }
    } else if ($scope.biztype == 1) { //团购
      $rjax.get({
        url: '/Home/Groupon/ajaxGetGponCartOrder',
        data: {
          set_id: $scope.setid,
          gpon_id: $scope.gponid
        },
        callback: function (response) {
          $debounce(function () {
            //noinspection JSUnresolvedVariable
            if (response.rsc == '1001') {
              if (empty(response.data.cart_list)) {
                $state.go('home');
              }
              $scope.cue = response.data.cue;
              $scope.cartInfo = response.data.cart_list.list;
              //noinspection JSUnresolvedVariable
              $scope.express = response.data.firstaddress;
              //noinspection JSUnresolvedVariable
              $scope.total_amount = response.data.cart_list.sum.sale_sum;
              $scope.shipping_fee = response.data.shipping_fee;
              $scope.sale_cycle = response.data.sale_cycle;
              $scope.dispatch_datetime = response.data.sale_cycle.dispatch_datetime.split(' ')[0];
            }
          });
        }
      })
    }
    $scope.visiable = false;
    $debounce(function () {
      $scope.visiable = true;
    }, 500);
    $scope.countSum = function () {
      var sum = num_f($scope.total_amount);
      if ($scope.shipping_fee != undefined) {
        sum += num_f($scope.shipping_fee);
      }
      $scope.truepay = sum;
      return sum;
    };
    $scope.checkSubmit = function () {
      if ($scope.cue != null && $scope.cue != undefined && $scope.cue != '') {
        var buttons = {
          '取消提交': function () {
            this.hide();
          },
          '继续提交': function () {
            $scope.submitOrder();
            this.hide();
          }
        };
        easy_dialog({
          buttons: buttons,
          content: $scope.cue
        });
      } else {
        $scope.submitOrder();
      }
    };
    $scope.submitOrder = function () {
      if ($scope.submit) {
        return false;
      }
      $scope.submit = true;
      if ($scope.express == null || $scope.express == undefined) {
        easy_dialog({
          content: '请设置您的快递地址'
        });
        return false;
      }
      if ($scope.biztype == 0) {
        //常规
        $rjax.post({
          url: '/Home/Order/ajaxAddOrder',
          data: {
            uda_id: $scope.express.uda_id,
            dispatch_datetime: $scope.sale_cycle.dispatch_datetime
          },
          callback: function (response) {
            //noinspection JSUnresolvedVariable
            if (response.rsc == '1001') {
              location.href = response.href;
            } else {
              $scope.submit = false;
              easy_dialog({
                content: response.msg
              })
            }
          }
        });
      } else if ($scope.biztype == 1) {
        //团购
        $rjax.post({
          url: '/Home/Groupon/ajaxAddGponOrder',
          data: {
            set_id: $state.params.setid,
            gpon_id: $state.params.gponid,
            uda_id: $scope.express.uda_id,
            dispatch_datetime: $scope.sale_cycle.dispatch_datetime
          },
          callback: function (response) {
            //noinspection JSUnresolvedVariable
            if (response.rsc == '1001') {
              location.href = response.href;
            } else {
              $scope.submit = false;
              easy_dialog({
                content: response.msg
              })
            }
          }
        });
      }

    }
  }])
  .controller('ExpressCtrl', ['$rootScope', '$scope', '$rjax', '$state', '$debounce', function ($rootScope, $scope, $rjax, $state, $debounce) {
    $rjax.get({
      url: '/Home/Login/ajaxCheckLogin',
      callback: function (response) {
        $debounce(function () {
          //noinspection JSUnresolvedVariable
          if (response.rsc == '1002') {
            $rootScope.showPanel = 'visiable';
          }
        });
      }
    });
    $scope.goBack = function () {
      if (!empty($scope.former)) {
        $state.go($scope.former, {
          biztype: $state.params.biztype,
          setid: $state.params.setid,
          gponid: $state.params.gponid
        });
      } else {
        $state.go('order');
      }
    };
    if (!empty($state.params.former)) {
      $scope.title = '地址管理';
      $scope.former = $state.params.former;
    } else {
      $scope.title = '地址选择';
      $scope.former = 'order';
    }
    //快递地址信息
    $scope.refreshUserExpressList = function () {
      $rjax.get({
        url: '/Home/Order/ajaxGetUserAddress',
        callback: function (response) {
          //noinspection JSUnresolvedVariable
          if (response.rsc == '1002') {
            $scope.expressList = null;
          } else {
            $scope.expressList = response.data;
          }
        }
      });
    };
    $scope.refreshUserExpressList();
    $scope.chooseExpress = function () {
      $state.go('home');
    };
    $scope.setDefault = function (index) {
      var uda_id = $scope.expressList[index].uda_id;
      var params = {
        uda_id: uda_id
      };
      $rjax.post({
        url: '/Home/Order/ajaxSetAddressDefault',
        data: params,
        callback: function (response) {
          //noinspection JSUnresolvedVariable
          if (response.rsc == '1001') {
            $scope.refreshUserExpressList();
            if ($scope.former == 'order') {
              $debounce(function () {
                $scope.goBack();
              }, 500);
            }
          } else { //noinspection JSUnresolvedVariable
            if (response.rsc == '1002') {
              easy_dialog({
                content: response.msg
              });
            }
          }
        }
      });
    };
    $scope.delete = function (index) {
      var uda_id = $scope.expressList[index].uda_id;
      var params = {
        uda_id: uda_id
      };
      var buttons = {
        '取消': function () {
          this.hide();
        },
        '删除': function () {
          this.hide();
          $rjax.post({
            url: '/Home/Order/ajaxDeleteOneAddress',
            data: params,
            callback: function (response) {
              //noinspection JSUnresolvedVariable
              if (response.rsc == '1001') {
                $scope.expressList.splice(index, 1);
              } else { //noinspection JSUnresolvedVariable
                if (response.rsc == '1002') {
                  easy_dialog({
                    content: response.msg
                  });
                }
              }
            }
          });
        }
      };
      easy_dialog({
        buttons: buttons,
        content: '确认删除这个地址吗？'
      });
    };
  }])
  .controller('ExpressOperateCtrl', ['$scope', '$rjax', '$state', '$debounce', function ($scope, $rjax, $state, $debounce) {
    $rjax.get({
      url: '/Home/Login/ajaxCheckLogin',
      callback: function (response) {
        $debounce(function () {
          //noinspection JSUnresolvedVariable
          if (response.rsc == '1002') {
            $rootScope.showPanel = 'visiable';
          }
        });
      }
    });
    //快递的地址信息
    $scope.getAddressConfig = (function () {
      $rjax.get({
        url: '/Home/Order/ajaxGetDistrict',
        data: {
          city_id: 1
        },
        callback: function (response) {
          //noinspection JSUnresolvedVariable
          if (response.rsc == '1001') {
            $scope.region_list = response.data;
          }
        }
      });
    })();
    $scope.getDistById = function (id) {
      var dname = '';
      var target = null;
      //noinspection JSUnresolvedVariable
      angular.forEach($scope.dist_list, function (data, index) {
        //noinspection JSUnresolvedVariable
        if (data.district_id == id) {
          //noinspection JSUnresolvedVariable
          dname = data.district_name;
          target = index;
          return true;
        }
      });
      return target;
    };
    $scope.getCityById = function (id) {
      var cname = '';
      var target = null;
      //noinspection JSUnresolvedVariable
      angular.forEach($scope.city_list, function (data, index) {
        if (data.city_id == id) {
          //noinspection JSUnresolvedVariable
          cname = data.city_name;
          target = index;
          return true;
        }
      });
      return target;
    };
    if ($state.params.operate == 'add') {
      $scope.headtitle = '添加地址';
      $scope.submit = function () {
        if ($scope.consignee == undefined) {
          easy_dialog({
            buttons: {
              '确认': function () {
                //noinspection JSUnresolvedFunction
                this.hide();
                var consigneeObj = angular.element(document.querySelector('input[name="consignee"]'));
                consigneeObj[0].focus();
              }
            },
            content: '收货人不能为空'
          });
          return false;
        }
        if ($scope.mobile == undefined || !validate_mobile($scope.mobile)) {
          easy_dialog({
            buttons: {
              '确认': function () {
                //noinspection JSUnresolvedFunction
                this.hide();
                var contactObj = angular.element(document.querySelector('input[name="mobile"]'));
                contactObj[0].focus();
              }
            },
            content: '请输入正确的手机号'
          });
          return false;
        }
        if ($scope.myDistSelect == undefined) {
          easy_dialog({
            buttons: {
              '确认': function () {
                //noinspection JSUnresolvedFunction
                this.hide();
                var districtObj = angular.element(document.querySelector('select[name="district"]'));
                districtObj[0].focus();
              }
            },
            content: '请选择一个区划'
          });
          return false;
        }
        if ($scope.address == undefined || $scope.address == '') {
          easy_dialog({
            buttons: {
              '确认': function () {
                //noinspection JSUnresolvedFunction
                this.hide();
                var addressObj = angular.element(document.querySelector('textarea[name="address"]'));
                addressObj[0].focus();
              }
            },
            content: '请输入您的详细地址'
          });
          return false;
        }
        $rjax.post({
          url: '/Home/Order/ajaxAddUserAddress',
          data: {
            consignee: $scope.consignee,
            mobile: $scope.mobile,
            city: 1,
            district: $scope.myDistSelect.region_id,
            address: $scope.address
          },
          callback: function (response) {
            //noinspection JSUnresolvedVariable
            if (response.rsc == '1001') {
              history.go(-1);
            }
          }
        });
      }
    } else {
      //noinspection JSUnresolvedVariable
      $scope.uda_id = $state.params.uid;
      $scope.headtitle = '修改地址';
      $scope.getInstExpress = (function () {
        $rjax.get({
          url: '/Home/Order/ajaxGetAddressInfoById',
          data: {
            uda_id: $scope.uda_id
          },
          callback: function (response) {
            //noinspection JSUnresolvedVariable
            if (response.rsc == '1001') {
              $scope.consignee = response.data.consignee;
              $scope.mobile = response.data.mobile;
              $scope.myDistSelect = {
                region_id: response.data.district
              };
              $scope.address = response.data.address;
            }
          }
        });
      })();
      $scope.submit = function () {
        if ($scope.consignee == undefined) {
          easy_dialog({
            buttons: {
              '确认': function () {
                //noinspection JSUnresolvedFunction
                this.hide();
                var consigneeObj = angular.element(document.querySelector('input[name="consignee"]'));
                consigneeObj[0].focus();
              }
            },
            content: '收货人不能为空'
          });
          return false;
        }
        if ($scope.mobile == undefined || !validate_mobile($scope.mobile)) {
          easy_dialog({
            buttons: {
              '确认': function () {
                //noinspection JSUnresolvedFunction
                this.hide();
                var contactObj = angular.element(document.querySelector('input[name="mobile"]'));
                contactObj[0].focus();
              }
            },
            content: '请输入正确的手机号'
          });
          return false;
        }
        if ($scope.myDistSelect == undefined) {
          easy_dialog({
            buttons: {
              '确认': function () {
                //noinspection JSUnresolvedFunction
                this.hide();
                var districtObj = angular.element(document.querySelector('select[name="district"]'));
                districtObj[0].focus();
              }
            },
            content: '请选择一个区划'
          });
          return false;
        }
        if ($scope.address == undefined || $scope.address == '') {
          easy_dialog({
            buttons: {
              '确认': function () {
                //noinspection JSUnresolvedFunction
                this.hide();
                var addressObj = angular.element(document.querySelector('textarea[name="address"]'));
                addressObj[0].focus();
              }
            },
            content: '请输入您的详细地址'
          });
          return false;
        }
        try {
          var params = {
            uda_id: $scope.uda_id,
            consignee: $scope.consignee,
            mobile: $scope.mobile,
            city: 1,
            district: $scope.myDistSelect.region_id,
            address: $scope.address
          };
        } catch (e) {
        }
        if (params != undefined) {
          $rjax.post({
            url: '/Home/Order/ajaxModifyAddress',
            data: params,
            callback: function (response) {
              //noinspection JSUnresolvedVariable
              if (response.rsc == '1001') {
                history.go(-1);
              }
            }
          });
        }
      }
    }
  }])
  .controller('PayCtrl', ['$rootScope', '$scope', '$rjax', '$state', '$debounce', function ($rootScope, $scope, $rjax, $state, $debounce) {
    $rjax.get({
      url: '/Home/Login/ajaxCheckLogin',
      callback: function (response) {
        $debounce(function () {
          //noinspection JSUnresolvedVariable
          if (response.rsc == '1002') {
            $rootScope.showPanel = 'visiable';
          }
        });
      }
    });
    $scope.orderid = $state.params.orderid;
    $scope.refresh = function () {
      $rjax.get({
        url: '/Home/Order/ajaxGetOrderInfo',
        data: {
          order_id: $scope.orderid
        },
        callback: function (response) {
          $debounce(function () {
            $scope.order_commoditys = response.data.order_commoditys;
            $scope.order_info = response.data.order_info;
            $scope.payment_info = response.data.payment_info;
            $scope.ship_info = response.data.ship_info;
          });
        }
      });
    };
    $scope.refresh();
    $scope.countNum = function () {
      var num = 0;
      angular.forEach($scope.order_commoditys, function (data) {
        //noinspection JSUnresolvedVariable
        num += num_f(data.order_num);
      });
      return num;
    };
    $scope.cancelOrder = function (orderid) {
      var buttons = {
        '不取消': function () {
          this.hide();
        },
        '确认取消': function () {
          this.hide();
          var data = {
            order_id: orderid
          };
          $rjax.post({
            url: '/Home/Order/ajaxCancelOrder',
            data: data,
            callback: function () {
              $state.go('ordercenter');
            }
          })
        }
      };
      easy_dialog({
        buttons: buttons,
        content: '确认要取消这个订单吗？'
      });
    };
    $scope.toPay = function () {
      $rjax.post({
        url: '/Home/Pay/ajaxSubmitPay',
        data: {
          payment_id: $scope.payment_info.payment_id,
          pay_type: 'wxmpay'
        },
        callback: function (response) {
          //noinspection JSUnresolvedVariable
          if (response.rsc == '1001') {
            //noinspection JSUnresolvedVariable
            location.href = 'http://m.shishifresh.com/Home/Wxmpay/index?flow_id=' + response.flow_id;
          }
        }
      })
    }
  }])
  .controller('CenterSettingPwdModifyCtrl', ['$scope', '$rjax', '$state', '$debounce', function ($scope, $rjax, $state, $debounce) {
    $scope.submit = function () {
      $rjax.post({
        url: '/Home/Account/ajaxUpdatePwd',
        data: {
          old_pwd: $scope.old_pwd ? hex_md5($scope.old_pwd) : null,
          new_pwd: $scope.new_pwd ? hex_md5($scope.new_pwd) : null,
          re_new_pwd: $scope.re_new_pwd ? hex_md5($scope.re_new_pwd) : null
        },
        callback: function (response) {
          //noinspection JSUnresolvedVariable
          if (response.rsc == '1001') {
            var buttons = {
              '确认': function () {
                this.hide();
                $debounce(function () {
                  $state.go('center');
                }, 300);
              }
            };
            easy_dialog({
              buttons: buttons,
              content: '修改成功'
            });
          } else {
            easy_dialog({content: response.msg});
          }
        }
      })
    }
  }])
  .controller('TuiXianCtrl', ['$scope', '$rjax', '$state', '$debounce', function ($scope, $rjax, $state, $debounce) {
    $scope.noWrapSlides = true;
    $scope.slides = [];
    $rjax.get({
      url: '/Home/BlockManage/ajaxGetTuiXianInfo',
      data: {
        bm_id: $state.params.bm_id
      },
      callback: function (response) {
        $debounce(function () {
          //noinspection JSUnresolvedVariable
          if (response.rsc == '1001') {
            $scope.slides = response.data.imgs;
            $scope.slides.push({});
            $scope.href = response.data.href;
          }
        });
      }
    });
    $scope.checkjump = function (index) {
      if ($scope.slides.length == index + 2) {
        location.href = $scope.href;
      }
    };
    $scope.toShare = false;
    $scope.toggleShare = function () {
      $scope.toShare = !$scope.toShare;
    };
  }])
  .controller('CategoryCtrl', ['$scope', '$rjax', '$state', '$debounce', function ($scope, $rjax, $state, $debounce) {
    $rjax.get({
      url: '/Home/Commodity/ajaxGetCommodityListByCateId',
      data: {
        cate_id: $state.params.cate_id
      },
      callback: function (response) {
        $debounce(function () {
          //noinspection JSUnresolvedVariable
          if (response.rsc == '1001') {
            $scope.list = response.data.commodity_list;
          }
        });
      }
    });
  }]);

